package com.dongdongshop.service.impl;

import com.alibaba.dubbo.config.annotation.Service;
import com.dongdongshop.mapper.seller.TbBrandMapper;
import com.dongdongshop.pojo.seller.TbBrand;
import com.dongdongshop.pojo.seller.TbBrandExample;
import com.dongdongshop.service.BrandService;
import com.dongdongshop.util.PageBean;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.sql.DataSource;
import java.util.List;

@Service
@Component
public class BrandServiceImpl implements BrandService {

    @Autowired
    private DataSource dataSource;

    @Autowired
    private TbBrandMapper brandMapper;

    @Override
    public PageBean<TbBrand> findBarandAll(Integer pageNumber, Integer pageSize) {
        PageBean<TbBrand> page = new PageBean<>();
        page.setPageNumber(pageNumber);
        page.setPageSize(pageSize);

        List<TbBrand> list = brandMapper.findBarandAll(page.getStartIndex(),pageSize);
        page.setResult(list);

        Integer count = brandMapper.getcount();
        page.setTotalCount(count);
        return page;
    }



    @Override
    public void insertBrandInfo(TbBrand brand) {
        brandMapper.insertSelective(brand);
    }

    @Override
    public TbBrand eachBrandInfo(Long id) {
        return brandMapper.selectByPrimaryKey(id);
    }

    @Override
    public void updateBrandById(TbBrand brand) {
        brandMapper.updateByPrimaryKeySelective(brand);
    }

    @Override
    public void deleteByIds(Long[] arr) {
        brandMapper.deleteByIds(arr);
    }

    @Override
    public List<TbBrand> getBrandAll() {
        List<TbBrand> list = brandMapper.selectByExample(new TbBrandExample());
        return list;
    }
}
